import request from '@/utils/request'
import { downloadFile } from './common'

const api = {
  contractSignLogQuery: '/custContract/signLog/query',
  contractTempQuery: '/contract/template/query',
  contractQuery: '/custContract/query',
  custBillQuery: '/custBill/query',
  updateTemp: 'contract/template/modify',
  markPay: '/custBill/markPay',
  syncNetSignStatus: 'custContract/syncNetSignStatus',
  editShelves: '/contract/template/modify/shelf',
  syncTempStatus: '/contract/template/sync',
  custContractDtl: '/custContract/detail',
  downloadNetSignWithCert: '/custContract/downloadNetSignWithCert',
  tempDtl: '/contract/template/detail',
  configTemp: '/contract/template/confParams'
}

/**
 * contractSignLogQuery func
 * parameter: {
 *     pageNum: '',
 *     pageSize: '',
 *     contractNo: '',
 *     templateKeyword: '',
 *     userKeyword'',
 *     merchantKeyword:'',
 *     signStatus:'',
 *     startCreateTime:'',
 *     endCreateTime:'',
 *     startSignCompleteTime:'',
 *     endSignCompleteTime:''
 * }
 * @param parameter
 * @returns {*}
 */
export function getContractSignLogList (parameter) {
  return request({
    url: api.contractSignLogQuery,
    method: 'post',
    data: parameter
  })
}

/**
 * contractTempQuery func
 * parameter: {
 *     pageNum: '',
 *     pageSize: '',
 *     templateNo: '',
 *     templateName: '',
 *     contractName'',
 *     isUpShelf:'',
 *     isConfigParams:'',
 *     templateType:''
 * }
 * @param parameter
 * @returns {*}
 */
export function getContractTempList (parameter) {
  return request({
    url: api.contractTempQuery,
    method: 'post',
    data: parameter
  })
}

/**
 * contractQuery func
 * parameter: {
 *     contractNo: '',
 *     templateKeyword: '',
 *     userKeyword: '',
 *     merchantKeyword: '',
 *     repaymentStatus:'',
 *     capitalContractStatus:'',
 *     serviceFeePayStatus:'',
 *     startCreateTime:'',
 *     endCreateTime:'',
 *     startSignCompleteTime:'',
 *     endSignCompleteTime:''
 * }
 * @param parameter
 * @returns {*}
 */
export function getContractList (parameter) {
  return request({
    url: api.contractQuery,
    method: 'post',
    data: parameter
  })
}

/**
 * custBillQuery func
 * parameter: {
 *     contractNo: '',
 *     userKeyword: '',
 *     merchantKeyword: '',
 *     repaymentSeq: '',
 *     billType:'',
 *     repaymentStatus:'',
 *     startShouldRepaymentTime:'',
 *     endShouldRepaymentTime:'',
 *     startActualRepaymentTime:'',
 *     endActualRepaymentTime:''
 * }
 * @param parameter
 * @returns {*}
 */
export function getCustBillList (parameter) {
  return request({
    url: api.custBillQuery,
    method: 'post',
    data: parameter
  })
}

/**
 * markPay func
 * parameter: {
 *     repaymentId: '',
 *     remark:''
 * }
 * @param parameter
 * @returns {*}
 */
export function markPay (parameter) {
  return request({
    url: api.markPay,
    method: 'post',
    data: parameter
  })
}

/**
 * syncNetSignStatus func
 * parameter: {
 *     contractNo: ''
 * }
 * @param parameter
 * @returns {*}
 */
export function syncNetSignStatus (parameter) {
  return request({
    url: api.syncNetSignStatus,
    method: 'post',
    data: parameter
  })
}

/**
 * editShelves func
 * parameter: {
 *     templateNo: '',
 *     isUpShelf:''
 * }
 * @param parameter
 * @returns {*}
 */
export function editShelves (parameter) {
  return request({
    url: api.editShelves,
    method: 'post',
    data: parameter
  })
}

/**
 * syncTempStatus func
 * parameter: {
 *     contractNo: ''
 * }
 * @param parameter
 * @returns {*}
 */
export function syncTempStatus (parameter) {
  return request({
    url: api.syncTempStatus,
    method: 'post',
    data: parameter
  })
}

/**
 * tempDtl func
 * parameter: {
 *     contractNo: ''
 * }
 * @param parameter
 * @returns {*}
 */
export function getTempDtl (parameter) {
  return request({
    url: api.tempDtl,
    method: 'post',
    data: parameter
  })
}

/**
 * custContractDtl func
 * parameter: {
 *     contractNo: ''
 * }
 * @param parameter
 * @returns {*}
 */
export function getCustContractDtl (parameter) {
  return request({
    url: api.custContractDtl,
    method: 'post',
    data: parameter
  })
}

/**
 * updateTemp func
 * parameter: {
 *     templateNo: '',
 *     contractName: '',
 *     contractDescribe: '',
 *     isSignSeq: '',
 *     contractType: '',
 *     templateType:'',
 *     iconUrl:''
 * }
 * @param parameter
 * @returns {*}
 */
export function updateTemp (parameter) {
  return request({
    url: api.updateTemp,
    method: 'post',
    data: parameter
  })
}

/**
 * configTemp func
 * parameter: {
 *     templateNo: '',
 *   paramsList:[],
 *   stepList:[]
 * }
 * @param parameter
 * @returns {*}
 */
export function configTemp (parameter) {
  return request({
    url: api.configTemp,
    method: 'post',
    data: parameter
  })
}

/**
 * downloadNetSignWithCert func
 * parameter: {
 *     contractNo: '',
 * }
 * @param parameter
 * @returns {*}
 */
export function downloadNetSignWithCert (parameter, cb) {
  downloadFile(api.downloadNetSignWithCert, parameter).then(() => {
    cb && cb()
  })
}
